toStrictlyNegativeIntOrNull

@ExperimentalSinceKotoolsTypes(version = "4.4")
fun Number.toStrictlyNegativeIntOrNull(): StrictlyNegativeInt?

Returns this number as a StrictlyNegativeInt, which may involve rounding or truncation, or returns null if this number is positive.

Here's some usage examples:

var result: StrictlyNegativeInt? = (-1).toStrictlyNegativeIntOrNull()
println(result) // -1

result = 0.toStrictlyNegativeIntOrNull()
println(result) // null

result = 1.toStrictlyNegativeIntOrNull()
println(result) // null

You can use the toStrictlyNegativeIntOrThrow function for throwing an IllegalArgumentException instead of returning null when this number is positive.